{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第一周进阶作业\n",
    "1.创建第一个视觉程序“Hello，world！”，显示Lena图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#hello openCV\n",
    "import cv2\n",
    "\n",
    "img = cv2.imread('lena512color.tiff')  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "不能使用中文路径  \n",
    "注意正反斜杠的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv2.imshow('Hello,world!', img)\n",
    "cv2.waitKey()\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![answer1](https://gitee.com/dkolli/first_week_homework/blob/master/answer1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.对Lena图像，分解得到RGB分量及HSV分量，显示各分量，并对结果进行比较说明。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "\n",
    "filename = 'lena512color.tiff'\n",
    "img=cv2.imread(filename)\n",
    "\n",
    "cv2.imshow('sourceImg', img)\n",
    "#展示原图\n",
    "hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)\n",
    "\n",
    "cv2.imshow('Hue', hsv[:,:, 0])\n",
    "#色调\n",
    "cv2.imshow('Saturation', hsv[:,:, 1])\n",
    "#饱和度\n",
    "cv2.imshow('Value', hsv[:,:, 2])\n",
    "#亮度\n",
    "\n",
    "cv2.imshow('blue', img[:,:, 0])\n",
    "cv2.imshow('green', img[:,:, 1])\n",
    "cv2.imshow('red', img[:,:, 2])\n",
    "\n",
    "cv2.waitKey()\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将彩色的lena图像分解成HSV分量  \n",
    " - 最左边的Hue是色调分量图，红色在HSV模型中对应0，0相当于全黑  \n",
    " - 中间的Saturation是饱和度分量图，越是纯色的颜色，其饱和度越高，显示的就越白  \n",
    " - 最右边的Value是亮度图，亮度越高，则显示的就越白"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![rgb2HSV](https://gitee.com/dkolli/first_week_homework/blob/master/HSV.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将彩色lena图分解成BGR分量\n",
    " - 最左边的是蓝色分量图\n",
    " - 中间的是绿色分量图\n",
    " - 最右边的是红色分量图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt rgb2BGR](https://gitee.com/dkolli/first_week_homework/blob/master/BGR.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
